home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / include / irit_sm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-19  |  7.8 KB  |  254 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, Jan. 1992   *
  5. ******************************************************************************
  6. * Main definition Header file  for Irit - the 3d polygonal solid modeller.   *
  7. *****************************************************************************/
  8.  
  9. #ifndef    IRIT_SM_H
  10. #define    IRIT_SM_H
  11.  
  12. /* Note program version should also be updated in *.c modules, in few        */
  13. /* places, as some system can not chain strings in the pre-processor level.  */
  14. #define  VERSION    "Version 5.0"             /* Program version. */
  15. #define  COPYRIGHT    "(C) Copyright 1989/90-95 Gershon Elber"
  16.  
  17. #include <math.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. #ifndef    NULL
  22. #define    NULL    0
  23. #endif /* NULL */
  24.  
  25. #ifndef    TRUE
  26. #define    TRUE    1
  27. #define    FALSE    0
  28. #endif /* TRUE */
  29.  
  30. #ifdef VoidPtr
  31. #undef VoidPtr
  32. #endif /* VoidPtr */
  33.  
  34. #ifdef NO_VOID_PTR
  35. #define VoidPtr        char *
  36. #else
  37. #define VoidPtr        void *
  38. #endif /* NO_VOID_PTR */
  39.  
  40. #if !defined(FLOAT) && !defined(DOUBLE)
  41. #if defined(__MSDOS__) || defined(MAKE_REAL_FLOAT)
  42. #define FLOAT
  43. typedef float           RealType;           /* On IBMPC to reserve memory... */
  44. #else
  45. #define DOUBLE
  46. typedef double          RealType;
  47. #endif /* __MSDOS__ || MAKE_REAL_FLOAT */
  48. #endif /* !FLOAT && !DOUBLE */
  49.  
  50. typedef    unsigned char    ByteType;
  51.  
  52. typedef    RealType    PointType[3];    /* For X, Y, Z coordinates of point. */
  53. typedef RealType    VectorType[3]; /* For X, Y, Z coordinates of vector. */
  54. typedef RealType    LineType[3];          /* A, B, C in Ax + By + C = 0. */
  55. typedef RealType    NormalType[3];        /* Unit normalized normal coeff. */
  56. typedef RealType    PlaneType[4];            /* Plane equation coeff. */
  57. typedef RealType    MatrixType[4][4];       /* Homogeneous transform. */
  58. typedef PointType    BBoxType[2];          /* Axis parallel bounding box. */
  59.  
  60. #define EPSILON        1e-5
  61. #define INFINITY    1e6
  62.  
  63. #ifndef M_PI
  64. #define M_PI    3.14159265358979323846
  65. #endif /* M_PI */
  66.  
  67. #define LINE_LEN_VLONG    1024           /* Lines read from stdin/files... */
  68. #define LINE_LEN_LONG    256           /* Lines read from stdin/files... */
  69. #define LINE_LEN    81           /* Lines read from stdin/files... */
  70. #define LINE_LEN_SHORT    31           /* Lines read from stdin/files... */
  71. #define OBJ_NAME_LEN    31                /* Names of objects. */
  72. #define FILE_NAME_LEN    13           /* Name (8) + Type (3) + Dot (1). */
  73. #define PATH_NAME_LEN    80                      /* Name with full Path */
  74.  
  75. /* Follows by general purpose helpfull macros: */
  76. #ifndef MIN
  77. #define MIN(x, y)        ((x) > (y) ? (y) : (x))
  78. #endif /* MIN */
  79. #ifndef MAX
  80. #define MAX(x, y)        ((x) > (y) ? (x) : (y))
  81. #endif /* MAX */
  82. #define BOUND(x, Min, Max)    (MAX(MIN((x), Max), Min))
  83.  
  84. #define ABS(x)            ((x) > 0 ? (x) : (-(x)))
  85. #define SQR(x)            ((x) * (x))
  86. #define SIGN(x)            ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
  87.  
  88. #define SWAP(type, x, y)    { type temp = (x); (x) = (y); (y) = temp; }
  89.  
  90. #define REAL_TO_INT(R)        ((int) ((R) > 0.0 ? (R) + 0.5 : (R) - 0.5))
  91. #define REAL_PTR_TO_INT(R)    REAL_TO_INT(*(R))
  92.  
  93. #define APX_EQ(x, y)        (ABS((x) - (y)) < EPSILON)
  94. #define APX_EQ_EPS(x, y, EPS)    (ABS((x) - (y)) < EPS)
  95. #define PT_APX_EQ(Pt1, Pt2)    (APX_EQ(Pt1[0], Pt2[0]) && \
  96.                  APX_EQ(Pt1[1], Pt2[1]) && \
  97.                  APX_EQ(Pt1[2], Pt2[2]))
  98. #define PT_APX_EQ_EPS(Pt1, Pt2, EPS) \
  99.                 (APX_EQ_EPS(Pt1[0], Pt2[0], EPS) && \
  100.                  APX_EQ_EPS(Pt1[1], Pt2[1], EPS) && \
  101.                  APX_EQ_EPS(Pt1[2], Pt2[2], EPS))
  102. #define PLANE_APX_EQ(Pl1, Pl2)    (APX_EQ(Pl1[0], Pl2[0]) && \
  103.                  APX_EQ(Pl1[1], Pl2[1]) && \
  104.                  APX_EQ(Pl1[2], Pl2[2]) && \
  105.                  APX_EQ(Pl1[3], Pl2[3]))
  106.  
  107. #ifdef DOUBLE
  108. #define IRIT_EPSILON        1e-14
  109. #else
  110. #define IRIT_EPSILON        1e-6
  111. #endif /* DOUBLE */
  112. #define IRIT_APX_EQ(x, y)        (ABS((x) - (y)) < IRIT_EPSILON)
  113. #define IRIT_PT_APX_EQ(Pt1, Pt2)    (IRIT_APX_EQ(Pt1[0], Pt2[0]) && \
  114.                      IRIT_APX_EQ(Pt1[1], Pt2[1]) && \
  115.                      IRIT_APX_EQ(Pt1[2], Pt2[2]))
  116.  
  117.  
  118. #define PT_CLEAR(Pt)        { Pt[0] = Pt[1] = Pt[2] = 0.0; }
  119.  
  120. #define PT_SCALE(Pt, Scalar)    { Pt[0] *= Scalar; \
  121.                   Pt[1] *= Scalar; \
  122.                   Pt[2] *= Scalar; \
  123.                     }
  124.  
  125. /* The memcpy is sometimes defined to get (char *) pointers and sometimes    */
  126. /* (void *) pointers. To be compatible with both it is coerced to (char *).  */
  127. #define UV_COPY(PtDest, PtSrc)      memcpy((char *) (PtDest), (char *) (PtSrc), \
  128.                             2 * sizeof(RealType))
  129. #define PT_COPY(PtDest, PtSrc)      memcpy((char *) (PtDest), (char *) (PtSrc), \
  130.                             3 * sizeof(RealType))
  131. #define PLANE_COPY(PlDest, PlSrc) memcpy((char *) (PlDest), (char *) (PlSrc), \
  132.                             4 * sizeof(RealType))
  133. #define MAT_COPY(Dest, Src)      memcpy((char *) (Dest), (char *) (Src), \
  134.                             16 * sizeof(RealType))
  135. #define GEN_COPY(Dest, Src, Size) memcpy((char *) (Dest), (char *) (Src), Size)
  136. #define ZAP_MEM(Dest, Size)      memset((char *) (Dest), 0, Size);
  137.  
  138. #define PT_SQR_LENGTH(Pt)    (SQR(Pt[0]) + SQR(Pt[1]) + SQR(Pt[2]))
  139. #define PT_LENGTH(Pt)        sqrt(SQR(Pt[0]) + SQR(Pt[1]) + SQR(Pt[2]))
  140.  
  141. #define PT_RESET(Pt)        Pt[0] = Pt[1] = Pt[2] = 0.0
  142. #define UV_RESET(Uv)        Uv[0] = Uv[1] = 0.0
  143.  
  144. #define PT_NORMALIZE_ZERO    1e-30
  145. #define PT_NORMALIZE(Pt)    {    RealType Size = PT_LENGTH(Pt); \
  146.                      if (Size < PT_NORMALIZE_ZERO) { \
  147.                      fprintf(stderr, "Attempt to normalize a zero length vector\n"); \
  148.                      } \
  149.                      else { \
  150.                      Pt[0] /= Size; \
  151.                      Pt[1] /= Size; \
  152.                          Pt[2] /= Size; \
  153.                      } \
  154.                 }
  155.  
  156. #define PT_BLEND(Res, Pt1, Pt2, t) \
  157.                 { Res[0] = Pt1[0] * t + Pt2[0] * (1 - t); \
  158.                   Res[1] = Pt1[1] * t + Pt2[1] * (1 - t); \
  159.                   Res[2] = Pt1[2] * t + Pt2[2] * (1 - t); \
  160.                     }
  161.  
  162. #define PT_ADD(Res, Pt1, Pt2)    { Res[0] = Pt1[0] + Pt2[0]; \
  163.                   Res[1] = Pt1[1] + Pt2[1]; \
  164.                   Res[2] = Pt1[2] + Pt2[2]; \
  165.                     }
  166.  
  167. #define PT_SUB(Res, Pt1, Pt2)    { Res[0] = Pt1[0] - Pt2[0]; \
  168.                   Res[1] = Pt1[1] - Pt2[1]; \
  169.                   Res[2] = Pt1[2] - Pt2[2]; \
  170.                 }
  171.  
  172. #define PT_SWAP(Pt1, Pt2)    { SWAP(RealType, Pt1[0], Pt2[0]); \
  173.                   SWAP(RealType, Pt1[1], Pt2[1]); \
  174.                   SWAP(RealType, Pt1[2], Pt2[2]); \
  175.                 }
  176.  
  177. #define PT_PT_DIST(Pt1, Pt2)    sqrt(SQR(Pt1[0] - Pt2[0]) + \
  178.                      SQR(Pt1[1] - Pt2[1]) + \
  179.                      SQR(Pt1[2] - Pt2[2]))
  180.  
  181. #define DOT_PROD(Pt1, Pt2)    (Pt1[0] * Pt2[0] + \
  182.                  Pt1[1] * Pt2[1] + \
  183.                  Pt1[2] * Pt2[2])
  184.  
  185. #define CROSS_PROD(PtRes, Pt1, Pt2) \
  186.                 { PtRes[0] = Pt1[1] * Pt2[2] - Pt1[2] * Pt2[1]; \
  187.                   PtRes[1] = Pt1[2] * Pt2[0] - Pt1[0] * Pt2[2]; \
  188.                   PtRes[2] = Pt1[0] * Pt2[1] - Pt1[1] * Pt2[0]; }
  189.  
  190. #define LIST_PUSH(New, List)       { (New) -> Pnext = (List); (List) = (New); }
  191. #define LIST_POP(Head, List)       { (Head) = (List); \
  192.                      (List) = (List) -> Pnext; \
  193.                      (Head) -> Pnext = NULL; }
  194. #define LIST_LAST_ELEM(Elem)       { if (Elem) \
  195.                      while ((Elem) -> Pnext) \
  196.                          (Elem) = (Elem) -> Pnext; }
  197.  
  198. #define DEG2RAD(Deg)        ((Deg) * M_PI / 180.0)
  199. #define RAD2DEG(Rad)        ((Rad) * 180.0 / M_PI)
  200.  
  201. #if defined(_AIX) || defined(sgi) || defined(DJGCC) || defined(OS2GCC) || defined(__WINNT__) || defined(AMIGA)
  202. #include <stdlib.h>
  203. #ifdef sgi
  204. #include <unistd.h>
  205. #endif /* sgi */
  206. #else
  207. VoidPtr malloc(unsigned int Size);
  208. void free(VoidPtr p);
  209. char *getenv(char *Name);
  210. int atoi(char *str);
  211. #endif /* _AIX || sgi || DJGCC || OS2GCC || __WINNT__ || AMIGA */
  212.  
  213. #if defined(__cplusplus) || defined(c_plusplus)
  214. extern "C" {
  215. #endif
  216.  
  217. char *IritStrdup(char *s);
  218. void IritSleep(int MiliSeconds);
  219. void IritRandomInit(long Seed);
  220. RealType IritRandom(RealType Min, RealType Max);
  221. RealType IritCPUTime(int Reset);
  222. char *IritRealTimeDate(void);
  223.  
  224. #ifndef AMIGA
  225. void movmem(VoidPtr Src, VoidPtr Dest, int Len);
  226. #endif /* AMIGA */
  227. char *searchpath(char *Name);
  228.  
  229. #ifdef STRICMP
  230. int strnicmp(char *s1, char *s2, int n);
  231. int stricmp(char *s1, char *s2);
  232. #endif /* STRICMP */
  233.  
  234. #ifdef STRSTR
  235. char *strstr(char *s, char *Pattern);
  236. #endif /* STRSTR */
  237.  
  238. #ifdef STRDUP
  239. char *strdup(char *s);
  240. #endif /* STRDUP */
  241.  
  242. #ifdef GETCWD
  243. char *getcwd(char *s, int Len);
  244. #endif /* GETCWD */
  245.  
  246. void IritFatalError(char *Msg);
  247. void IritWarningError(char *Msg);
  248.  
  249. #if defined(__cplusplus) || defined(c_plusplus)
  250. }
  251. #endif
  252.  
  253. #endif    /* IRIT_SM_H */
  254.